#coding=utf-8

rank_dict = {'界':'kindom',
             '门':'phylum',
             '纲':'class_',
             '目':'order',
             '科':'family',
             '属':'genus',
             '种':'species'}

def remove_blank(s):
    return ''.join(s.split(' '))           

class Name(object):
    def __init__(self, zh='', latin=''):
        self.name_latin = remove_blank( latin )
        self.name_zh = remove_blank( zh )
        
        
    def get_rank(self):
        for k in rank_dict.keys():
            if self.name_zh.find(k) != -1:
                return rank_dict[k]
        return 'species'
    
    def __repr__(self):
        return ' '.join( [self.name_zh,self.name_latin] )
        
class Species(object):
    attrs = ['kindom', 'phylum', 'class_', 'order', 'family', 'genus', 'species']
    
    def __init__(self):
        for attr in self.attrs:
            setattr(self, attr, None)
    
    def __repr__(self):
        s = []
        for a in self.attrs:
            if a == 'genus':continue
            n = getattr(self, a)
            if n:
                s.append(str(n))
        return '\t'.join(s)    
        
def get_name(line):
    line = line.strip()
    i = line.find(' ')
    a, b = line[:i], line[i+1:]
    #print a,b
    return Name( a, b )
    
cs = Species()
for l in file('zl.txt'):
    l = l.strip()
    if not l:continue
    n = get_name(l)
    r = n.get_rank()
    setattr(cs, r, n)
    if r == 'species':
        print cs
        


